package com.share;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;

public class BaseActivity extends Activity {

	private boolean isLogined = false;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.isLogined = this._isLogined();
	}

	/**
	 * get is login
	 * 
	 * @return boolean
	 */
	public boolean getIsLogined() {
		return this.isLogined;
	}

	/**
	 * Login the system
	 * 
	 * @author Tien Nguyen
	 * @return boolean
	 */
	private boolean _isLogined() {
		boolean isLogin = false;

		// String username = getResources().getString(R.string.username);
		// String password = getResources().getString(R.string.password);

		SharedPreferences settings = getSharedPreferences("pref_login", 0);
		Log.d("Tien", "Log : "+settings.toString()); 
		if (settings != null) {
			String username = settings.getString("username", "");
			String password = settings.getString("password", "");

			Log.d("Tien", "Pref username : " + username);
			Log.d("Tien", "Pref password : " + password);

			if (!username.equals("") && !password.equals("")) {
				Log.d("Tien", "Vao login");
				isLogin = true;
			}
			
			Log.d("Tien", "End login");
		}

		return isLogin;
	}
}
